﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Microhard.Permission.Models;

namespace Microhard.Permission.Validator
{
    public class DictionaryModelValidator : AbstractValidator<DictionaryModel>
    {
        public DictionaryModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Name).NotEmpty().WithMessage(MsgForPermission.NeedDicName).When(m=>m.DataID == Guid.Empty);
                RuleFor(u => u.Name).Length(1, 50).WithMessage(MsgForPermission.MaxDicName).When(m => m.DataID == Guid.Empty);
                RuleFor(u => u.Type).NotEmpty().WithMessage(MsgForPermission.NeedDicType).When(m => m.DataID == Guid.Empty);
                RuleFor(u => u.Type).Length(6, 20).WithMessage(MsgForPermission.MaxDicType).When(m => m.DataID == Guid.Empty);
            });

            RuleSet("Update", () =>
            {
                RuleFor(u => u.Name).NotEmpty().WithMessage(MsgForPermission.NeedDicName);
                RuleFor(u => u.Name).Length(1, 50).WithMessage(MsgForPermission.MaxDicName);
                RuleFor(u => u.Type).NotEmpty().WithMessage(MsgForPermission.NeedDicType);
                RuleFor(u => u.Type).Length(6, 20).WithMessage(MsgForPermission.MaxDicType);
            });
        }
    }
}
